package controllers

import (
	"crawl_movie/models"
	"crawl_movie/util"
	"github.com/astaxie/beego"
)

type CrawlMovieController struct {
	beego.Controller
}

func(c *CrawlMovieController) List() {
	pageNo, _ := c.GetInt("pageNo")
	if pageNo == 0 {
		pageNo = 1
	}
	MovieName := c.GetString("MovieName")
	MovieType := c.GetString("type")
	MovieCountry := c.GetString("country")
	order := c.GetString("order")
	c.Data["page"] = models.MovieList(pageNo, MovieName, order, MovieType, MovieCountry)
	c.Data["MovieName"] = MovieName
	c.Data["order"] = order
	c.Data["type"] = MovieType
	c.Data["country"] = MovieCountry
	c.TplName = "movie/list.tpl"
}

func(c *CrawlMovieController) Info() {
	id, _ := c.GetInt64("id")
	c.Data["movieInfo"] = models.MovieInfoView(id)
	c.TplName = "movie/info.tpl"
}

func(c *CrawlMovieController) CountryList() {
	c.Data["json"] = models.MovieInfoCountry()
	c.ServeJSON()
}

func(c *CrawlMovieController) TypeList() {
	c.Data["json"] = models.MovieInfoType()
	c.ServeJSON()
}

func (c *CrawlMovieController) GetThreadStart() {
	res := make(map[string]interface{})
	res["flag"] = util.IsRun
	c.Data["json"] = res
	c.ServeJSON()
}

func (c *CrawlMovieController) ThreadStart() {
	util.IsRun = !util.IsRun
	res := make(map[string]interface{})
	res["flag"] = util.IsRun
	c.Data["json"] = res
	c.ServeJSON()
}